#include "phylink.h"
#include "uartdevice.h"
#include "tcpdevice.h"

IPhyLink::IPhyLink() :
    settings_(nullptr)
{

}

IPhyLink::~IPhyLink()
{
    if (settings_)
        delete settings_;
}

IPhyLink *IPhyLink::createDev(ComSettings *settings)
{
    IPhyLink * dev = nullptr;

    if (settings->is_uart)
    {
        dev = new UartDevice(settings->dev_name.c_str(), settings->uart.baudrate, settings->uart.parity, true);
    }
    else
    {
        dev = new TcpDevice(settings->dev_name.c_str(), settings->tcp.ip.c_str(), settings->tcp.port);
    }

    dev->settings_ = settings;

    return dev;
}

uint32_t IPhyLink::read(void *buf, uint32_t max_byte)
{
    return 0;
}
